﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Diagnostics;

namespace SimpleIR
{
	/// <summary>
	/// Base class for types in the SimpleIR program representation.
	/// </summary>
	public abstract class IRType : IComparable<IRType>
	{
		/// <summary>
		/// A unique identifier for each type.
		/// </summary>
		public readonly int TypeID;

		/// <summary>
		/// The full name of the type.
		/// </summary>
		public readonly string TypeName;

		/// <summary>
		/// The namespace + any enclosing type names.
		/// </summary>
		public readonly string NameSpaceAndEnclosing;
		
		/// <summary>
		/// The unqualified name of the type.
		/// </summary>
		public readonly string BaseTypeName;

		/// <summary>
		/// Additional specifications on the structure of the type.
		/// </summary>
		public readonly IRTypeDescription TypeDescription;

		/// <summary>
		/// Construct a type given the namespace (null if default namespace), enclosing types (null if no enclosing types), and base type name.
		/// </summary>
		protected IRType(int typeid, string tnamespace, string tbasename, TypeQualifiers tqual)
		{
			this.TypeID = typeid;

			string nss = (!String.IsNullOrEmpty(tnamespace)) ? (tnamespace + ".") : "";
			this.TypeName = nss + tbasename;

			this.NameSpaceAndEnclosing = tnamespace;
			this.BaseTypeName = tbasename;

			this.TypeDescription = new IRTypeDescription(this, tqual);
		}

		public override string ToString()
		{ return this.TypeName; }

		public int CompareTo(IRType other)
		{ return this.TypeID - other.TypeID; }

		public override int GetHashCode()
		{ return this.TypeID; }

		public override bool Equals(object obj)
		{ return this == obj; }
	}
}
